package com.keiou.drink.api.remote;


import com.keiou.drink.api.ApiService;
import com.keiou.drink.api.HttpUrl;
import com.keiou.drink.api.ServiceFactory;
import com.keiou.drink.request.AppInfoReq;
import com.keiou.drink.request.ProductListReq;
import com.keiou.drink.request.Pwd;
import com.keiou.drink.request.SubmitOrderReq;
import com.keiou.drink.response.AppInfo;
import com.keiou.drink.response.MachineStatusRes;
import com.keiou.drink.response.OrderHistoryRes;
import com.keiou.drink.response.OrderMsgRes;
import com.keiou.drink.response.OrderStatusRes;
import com.keiou.drink.response.ProductListRes;
import com.keiou.drink.response.ResetStockRes;
import com.keiou.drink.response.VoiceStatusRes;
import com.keiou.drink.response.base.HttpResult;

import rx.Observable;


/**
 * 作者 ：Bob on 2017/6/1.
 * 邮箱 ：motherlovefather@126.com
 */

public class Api {

    private static ApiService apiService;
    private static Api mmApi;

    public static synchronized ApiService getApiService() {
        if (null == apiService) {
            apiService = ServiceFactory.createService(HttpUrl.BASE_URL, ApiService.class);
        }
        return apiService;
    }

    private Api() {
        apiService = ServiceFactory.createService(HttpUrl.BASE_URL, ApiService.class);
    }

    public static synchronized Api getInstance() {
        if (null == mmApi) {
            mmApi = new Api();
        }
        return mmApi;
    }


    public Observable<HttpResult<AppInfo>> getAppInfo(String deviceType, String version) {
        AppInfoReq req = new AppInfoReq(deviceType, version);
        return apiService.getAppInfo(req);
    }

    /**
     * 商品列表
     * @param deviceId
     * @return
     */
    public Observable<HttpResult<ProductListRes>> getProductList(String deviceId) {
        return apiService.getProductList(deviceId);
    }

    /**
     * 提交订单
     * @param padId
     * @param productId
     * @param salesPrice
     * @param count
     * @param amount
     * @return
     */
    public Observable<HttpResult<OrderMsgRes>> submitOrder(String padId, String productId, String salesPrice, String count, String amount, String temperature, String attrCode) {

        return apiService.submitOrder(padId, productId, salesPrice, count, amount, temperature, attrCode);
    }

    /**
     * 订单状态
     * @param padId
     * @param orderId
     * @return
     */
    public Observable<HttpResult<OrderStatusRes>> getOrderStatus(String padId, String orderId){
        return apiService.getOrderStatus(padId, orderId);
    }

    /**
     * 管理员登录
     * @param id
     * @param pwd
     * @return
     */
    public Observable<HttpResult<Pwd>> login(String id, String pwd){
        return apiService.login(id, pwd);
    }

    /**
     * 恢复库存
     * @param padId
     * @return
     */
    public Observable<HttpResult<ResetStockRes>> resetStock(String padId){
        return apiService.resetStock(padId);
    }

    /**
     * 机器状态
     * @param padId
     * @return
     */
    public Observable<HttpResult<MachineStatusRes>> getMachineStatus(String padId){
        return apiService.getMachineStatus(padId);
    }

    /**
     * 声音
     * @param padId
     * @return
     */
    public Observable<HttpResult<VoiceStatusRes>> getVoiceStatus(String padId){
        return apiService.getVoiceStatus(padId);
    }

    /**
     * 订单列表
     * @return
     */
    public Observable<HttpResult<OrderHistoryRes>>getOrderList(String padId){
        return apiService.getOrderList(padId);
    }


}
